import Vue from 'vue'
import Vuex from 'vuex'
import BottomTabs from './bottom-tabs'
import TheBook from './the-book'
import Wallet from './wallet'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    systemInfo: {}
  },

  getters: {
    isIphoneX(state) {
      return /iphone.*?x/g.test(state.systemInfo.model.toLowerCase())
    }
  },
  mutations: {
    setSystemInfoSync(state, info) {
      state.systemInfo = info
    }
  },
  actions: {
    getSystemInfo({ commit }) {
      try {
        const info = wx.getSystemInfoSync()
        commit('setSystemInfoSync', info)
      } catch (err) {
        console.error(err)
      }
    }
  },
  modules: { BottomTabs, TheBook, Wallet }
})
